'''
Language parser for Rust lang
'''

from .code_reader import CodeReader
from .clike import CCppCommentsMixin
from .golike import GoLikeStates


class RustReader(CodeReader, CCppCommentsMixin):
    # pylint: disable=R0903

    ext = ['rs']
    language_names = ['rust']
    
    # Separated condition categories
    _control_flow_keywords = {'if', 'for', 'while', 'catch', 'match', 'where'}
    _logical_operators = {'&&', '||'}
    _case_keywords = set()  # Rust uses match arms, not case keyword
    # Note: '?' in Rust is the error propagation operator, not ternary
    _ternary_operators = {'?'}

    def __init__(self, context):
        super().__init__(context)
        self.parallel_states = [RustStates(context)]

    @staticmethod
    def generate_tokens(source_code, addition='', token_class=None):
        addition = r"|(?:'\w+\b)"  # lifetimes, labels
        return CodeReader.generate_tokens(source_code, addition, token_class)


class RustStates(GoLikeStates):  # pylint: disable=R0903
    FUNC_KEYWORD = 'fn'
